//
// Created by 28365 on 2025/3/5.
//

#ifndef ODUPDATERSDK_REQVALUE_H
#define ODUPDATERSDK_REQVALUE_H

#include <string>
#include <nlohmann/json.hpp>

#include "../include/config/server_api/ServerAPIState.h"

using namespace std;

typedef nlohmann::json json;

/**
 * 请求返回值
 */
template<typename T>
class ReqValue {

private:

    /**
     * API返回状态
     */
    ServerAPIState serverAPIState = SUCCESS;

    /**
     * 错误信息
     */
    string message{};

    /**
     * 数据
     */
    T data{};

public:

    [[maybe_unused]] ReqValue(string data, ServerAPIState serverApiState, string message);

    ReqValue() = default;

    [[maybe_unused]] [[nodiscard]] T &getData();

    void setData(const T &data);

    [[nodiscard]] ServerAPIState getServerApiState() const;

    void setServerApiState(ServerAPIState serverApiState);

    [[nodiscard]] const string &getMessage() const;

    void setMessage(const string &message);
};

template<typename T>
[[maybe_unused]] T &ReqValue<T>::getData(){
    return data;
}

template<typename T>
void ReqValue<T>::setData(const T &_data) {
    ReqValue::data = _data;
}

template<typename T>
[[maybe_unused]] ServerAPIState ReqValue<T>::getServerApiState() const {
    return serverAPIState;
}

template<typename T>
void ReqValue<T>::setServerApiState(ServerAPIState serverApiState) {
    serverAPIState = serverApiState;
}

template<typename T>
[[maybe_unused]] ReqValue<T>::ReqValue(string data, ServerAPIState serverApiState, string message) : data(std::move(data)),
                                                                                                     serverAPIState(
                                                                                                             serverApiState),
                                                                                                     message(std::move(message)) {}

template<typename T>
const string &ReqValue<T>::getMessage() const {
    return message;
}

template<typename T>
void ReqValue<T>::setMessage(const string &_message) {
    ReqValue::message = _message;
}


#endif //ODUPDATERSDK_REQVALUE_H
